.class public Lcom/zuiapps/suite/utils/shell/ShellUtil;
.super Ljava/lang/Object;
.source "ShellUtil.java"


# direct methods
.method public constructor <init>()V
    .registers 1

    .prologue
    .line 10
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method private static inputStreamToString(Ljava/io/InputStream;)Ljava/lang/String;
    .registers 6
    .param p0, "in"    # Ljava/io/InputStream;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 51
    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    .line 52
    .local v2, "out":Ljava/lang/StringBuffer;
    const/16 v3, 0x400

    new-array v0, v3, [B

    .line 53
    .local v0, "b":[B
    :goto_9
    invoke-virtual {p0, v0}, Ljava/io/InputStream;->read([B)I

    move-result v1

    .local v1, "n":I
    const/4 v3, -0x1

    if-eq v1, v3, :cond_1a

    .line 54
    new-instance v3, Ljava/lang/String;

    const/4 v4, 0x0

    invoke-direct {v3, v0, v4, v1}, Ljava/lang/String;-><init>([BII)V

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    goto :goto_9

    .line 56
    :cond_1a
    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v3

    return-object v3
.end method

.method public static runRootCmd(Ljava/lang/String;)Ljava/lang/String;
    .registers 2
    .param p0, "command"    # Ljava/lang/String;

    .prologue
    .line 12
    const-string v0, ";"

    invoke-static {p0, v0}, Lcom/zuiapps/suite/utils/shell/ShellUtil;->runRootCmd(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public static runRootCmd(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .registers 15
    .param p0, "command"    # Ljava/lang/String;
    .param p1, "split"    # Ljava/lang/String;

    .prologue
    .line 16
    const/4 v6, 0x0

    .line 17
    .local v6, "process":Ljava/lang/Process;
    const/4 v4, 0x0

    .line 18
    .local v4, "os":Ljava/io/DataOutputStream;
    const-string v7, "false"

    .line 20
    .local v7, "result":Ljava/lang/String;
    :try_start_4
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v10

    const-string v11, "su"

    invoke-virtual {v10, v11}, Ljava/lang/Runtime;->exec(Ljava/lang/String;)Ljava/lang/Process;

    move-result-object v6

    .line 21
    invoke-virtual {v6}, Ljava/lang/Process;->getOutputStream()Ljava/io/OutputStream;

    move-result-object v5

    .line 22
    .local v5, "outstream":Ljava/io/OutputStream;
    new-instance v1, Ljava/io/DataOutputStream;

    invoke-direct {v1, v5}, Ljava/io/DataOutputStream;-><init>(Ljava/io/OutputStream;)V

    .line 23
    .local v1, "dataOutputStream":Ljava/io/DataOutputStream;
    const-string v9, ""

    .line 24
    .local v9, "temp":Ljava/lang/String;
    invoke-virtual {p0, p1}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String;

    move-result-object v0

    .line 25
    .local v0, "cmds":[Ljava/lang/String;
    const/4 v3, 0x0

    .local v3, "i":I
    :goto_1e
    array-length v10, v0

    if-ge v3, v10, :cond_3d

    .line 26
    new-instance v10, Ljava/lang/StringBuilder;

    invoke-direct {v10}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v10, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    aget-object v11, v0, v3

    invoke-virtual {v10, v11}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    const-string v11, "\n"

    invoke-virtual {v10, v11}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    invoke-virtual {v10}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    .line 25
    add-int/lit8 v3, v3, 0x1

    goto :goto_1e

    .line 27
    :cond_3d
    invoke-virtual {v1, v9}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

    .line 28
    invoke-virtual {v1}, Ljava/io/DataOutputStream;->flush()V

    .line 29
    const-string v10, "exit\n"

    invoke-virtual {v1, v10}, Ljava/io/DataOutputStream;->writeBytes(Ljava/lang/String;)V

    .line 30
    invoke-virtual {v1}, Ljava/io/DataOutputStream;->flush()V

    .line 31
    invoke-virtual {v6}, Ljava/lang/Process;->waitFor()I

    .line 32
    invoke-virtual {v6}, Ljava/lang/Process;->getInputStream()Ljava/io/InputStream;

    move-result-object v10

    invoke-static {v10}, Lcom/zuiapps/suite/utils/shell/ShellUtil;->inputStreamToString(Ljava/io/InputStream;)Ljava/lang/String;
    :try_end_55
    .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_55} :catch_6b
    .catchall {:try_start_4 .. :try_end_55} :catchall_8a

    move-result-object v7

    .line 39
    if-eqz v4, :cond_5b

    .line 40
    :try_start_58
    invoke-virtual {v4}, Ljava/io/DataOutputStream;->close()V

    .line 42
    :cond_5b
    invoke-virtual {v6}, Ljava/lang/Process;->destroy()V
    :try_end_5e
    .catch Ljava/lang/Exception; {:try_start_58 .. :try_end_5e} :catch_60

    :goto_5e
    move-object v8, v7

    .line 47
    .end local v0    # "cmds":[Ljava/lang/String;
    .end local v1    # "dataOutputStream":Ljava/io/DataOutputStream;
    .end local v3    # "i":I
    .end local v5    # "outstream":Ljava/io/OutputStream;
    .end local v7    # "result":Ljava/lang/String;
    .end local v9    # "temp":Ljava/lang/String;
    .local v8, "result":Ljava/lang/String;
    :goto_5f
    return-object v8

    .line 43
    .end local v8    # "result":Ljava/lang/String;
    .restart local v0    # "cmds":[Ljava/lang/String;
    .restart local v1    # "dataOutputStream":Ljava/io/DataOutputStream;
    .restart local v3    # "i":I
    .restart local v5    # "outstream":Ljava/io/OutputStream;
    .restart local v7    # "result":Ljava/lang/String;
    .restart local v9    # "temp":Ljava/lang/String;
    :catch_60
    move-exception v2

    .line 44
    .local v2, "e":Ljava/lang/Exception;
    const-string v10, ""

    invoke-virtual {v2}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v11

    invoke-static {v10, v11}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_5e

    .line 34
    .end local v0    # "cmds":[Ljava/lang/String;
    .end local v1    # "dataOutputStream":Ljava/io/DataOutputStream;
    .end local v2    # "e":Ljava/lang/Exception;
    .end local v3    # "i":I
    .end local v5    # "outstream":Ljava/io/OutputStream;
    .end local v9    # "temp":Ljava/lang/String;
    :catch_6b
    move-exception v2

    .line 35
    .restart local v2    # "e":Ljava/lang/Exception;
    :try_start_6c
    const-string v10, ""

    invoke-virtual {v2}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v11

    invoke-static {v10, v11}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I
    :try_end_75
    .catchall {:try_start_6c .. :try_end_75} :catchall_8a

    .line 39
    if-eqz v4, :cond_7a

    .line 40
    :try_start_77
    invoke-virtual {v4}, Ljava/io/DataOutputStream;->close()V

    .line 42
    :cond_7a
    invoke-virtual {v6}, Ljava/lang/Process;->destroy()V
    :try_end_7d
    .catch Ljava/lang/Exception; {:try_start_77 .. :try_end_7d} :catch_7f

    :goto_7d
    move-object v8, v7

    .line 45
    .end local v7    # "result":Ljava/lang/String;
    .restart local v8    # "result":Ljava/lang/String;
    goto :goto_5f

    .line 43
    .end local v8    # "result":Ljava/lang/String;
    .restart local v7    # "result":Ljava/lang/String;
    :catch_7f
    move-exception v2

    .line 44
    const-string v10, ""

    invoke-virtual {v2}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v11

    invoke-static {v10, v11}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_7d

    .line 38
    .end local v2    # "e":Ljava/lang/Exception;
    :catchall_8a
    move-exception v10

    .line 39
    if-eqz v4, :cond_90

    .line 40
    :try_start_8d
    invoke-virtual {v4}, Ljava/io/DataOutputStream;->close()V

    .line 42
    :cond_90
    invoke-virtual {v6}, Ljava/lang/Process;->destroy()V
    :try_end_93
    .catch Ljava/lang/Exception; {:try_start_8d .. :try_end_93} :catch_94

    .line 45
    :goto_93
    throw v10

    .line 43
    :catch_94
    move-exception v2

    .line 44
    .restart local v2    # "e":Ljava/lang/Exception;
    const-string v11, ""

    invoke-virtual {v2}, Ljava/lang/Exception;->getMessage()Ljava/lang/String;

    move-result-object v12

    invoke-static {v11, v12}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_93
.end method
